package com.xuecheng.content.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.api.media.model.MediaDTO;
import com.xuecheng.common.domain.code.CommonErrorCode;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.content.entity.TeachplanMedia;
import com.xuecheng.content.service.TeachplanMediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class TeachplanMediaController {

    @Autowired
    private TeachplanMediaService  teachplanMediaService;
    @GetMapping("/l/TeachplanMedia/{mediaId}")
    public RestResponse<TeachplanMedia> getTeachplanByMediaId(@PathVariable Long mediaId){
        LambdaQueryWrapper<TeachplanMedia> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TeachplanMedia::getMediaId,mediaId);
        List<TeachplanMedia> list = teachplanMediaService.list(queryWrapper);
        TeachplanMedia teachplanMedia =null;
        if (!ObjectUtils.isEmpty(list)){
           if (list.size()<0){
               teachplanMedia=null;
           }else {
               teachplanMedia = list.get(0);
           }
        }else {
            teachplanMedia=null;
        }
        RestResponse<TeachplanMedia> response = new RestResponse();
        response.setCode(CommonErrorCode.SUCCESS.getCode());
        response.setMsg("丫丫");
        response.setResult(teachplanMedia);
        return response;
    }

}
